/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ControlLayer;

import DBLayer.*;
import ModelLayer.*;
import java.util.ArrayList;
import java.util.Date;

/**
 *
 * @author Hedevilla
 */
public class SaleController
{   
    private DBSalesContainer salesContainer;
    private DBInvoiceContainer invoiceContainer;
    private DBSalesLineContainer salesLineContainer;
    private DBProductContainer productContainer;

    public SaleController()
    {
        invoiceContainer = new DBInvoiceContainer();
        salesContainer = DBSalesContainer.getInstance();
        salesLineContainer = DBSalesLineContainer.getInstance();
    }

    public SalesLine createSalesLine(int productID, int amount)
    {
        SalesLine sl = new SalesLine(amount, produktID);
        ArrayList<SalesLine> lol = new ArrayList<SalesLine>();
        lol.add(SalesLineen);
    }

    public ArrayList<SalesOrder> getSales()
    {
        return salesContainer.getOrders();
    }

    public ArrayList<SalesOrder> getSales(int customerID)
    {
        return salesContainer.getOrders(customerID);
    }

    public void createSale(int customerID, int employeeID, Date Paymentdate, ArrayList<SalesLine> salesline)
    {
        //getperson
        Date daysDate = new Date();
        Date deliverydate = new Date();
        deliverydate.setDate(daysDate.getDate() + 5);
        //int SaleOrderID = salesContainer.getNewestSalesOrderID();
        createInvoice(Paymentdate);
        int InvoiceID = invoiceContainer.getNewestInvoiceID();

        SalesOrder so = new SalesOrder(customerID, employeeID, daysDate, "Afvendter betaling", deliverydate, InvoiceID);
        salesContainer.addSalesOrder(so);

        //Looper alle salesline igennem og tilføjes til liste
        for (int i = 0; i < salesline.size(); i++) {
            SalesLine line = salesline.get(i);
            line.setSalesOrder(so);
            salesLineContainer.addSalesLine(salesline.get(i));
        }
    }

    public void createInvoice(Date Paymentdate)
    {

        Invoice iv = new Invoice(Paymentdate);
        invoiceContainer.createInvoice(iv);

    }


}
